package com.wdh.kjs.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wdh.kjs.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by lyh on 2016/9/12 0012.
 */
public class MF_invest_Adapter2 extends BaseAdapter {
    private List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    private Context context;
    private HashMap<String, String> maps = new HashMap<String, String>();
    private int periods = 0;

    public MF_invest_Adapter2(Context context, List<HashMap<String, String>> data) {
        this.data = data;
        this.context = context;
    }

    public void resetData(List<HashMap<String, String>> data) {
        this.data.clear();
        this.data.addAll(data);
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();

            convertView = View.inflate(context, R.layout.fragment_finance_flowing2, null);

//            viewHolder.moneyFlowing_type = (TextView) convertView
//                    .findViewById(R.id.moneyFlowing_type);
            viewHolder.moneyFlowing_name = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_name2);
            viewHolder.moneyFlowing_abstract = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_abstract2);
            viewHolder.moneyFlowing_annualRate = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_annualRate2);
            viewHolder.moneyFlowing_projectTime = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_projectTime2);
            viewHolder.moneyFlowing_repayType = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_repayType2);
            viewHolder.moneyFlowing_investMoney = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_investMoney2);
            viewHolder.moneyFlowing_payMode = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_payMode2);
            viewHolder.moneyFlowing_startTime = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_startTime2);
         /*   viewHolder.moneyFlowing_availableBalance = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_availableBalance2);*/
            viewHolder.moneyFlowing_blockedBalance = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_blockedBalance2);
            viewHolder.moneyFlowing_cash = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_cash2);
            viewHolder.moneyFlowing_earning = (TextView) convertView
                    .findViewById(R.id.moneyFlowing_earning2);
//            convertView.findViewById(R.id.bt_mifs_payment_detail).setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    ToastUtils.showShort(context, "跳到回款详情界面");
//                    Intent it = new Intent(context, RepaymentDetailsActivity.class);
//                    context.startActivity(it);
//                }
//            });
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        maps = data.get(position);
//        viewHolder.moneyFlowing_type.setText(maps.get("moneyFlowing_type"));
        viewHolder.moneyFlowing_name.setText(maps.get("moneyFlowing_name"));
        viewHolder.moneyFlowing_abstract.setText(maps.get("moneyFlowing_abstract"));
        viewHolder.moneyFlowing_annualRate.setText(maps.get("moneyFlowing_annualRate"));
        viewHolder.moneyFlowing_projectTime.setText(maps.get("moneyFlowing_projectTime"));
        viewHolder.moneyFlowing_repayType.setText(maps.get("moneyFlowing_repayType"));
        viewHolder.moneyFlowing_investMoney.setText(maps.get("moneyFlowing_investMoney"));
        viewHolder.moneyFlowing_payMode.setText(maps.get("moneyFlowing_payMode"));
        viewHolder.moneyFlowing_startTime.setText(maps.get("moneyFlowing_startTime"));
        //viewHolder.moneyFlowing_availableBalance.setText(maps.get("moneyFlowing_availableBalance"));
        viewHolder.moneyFlowing_blockedBalance.setText(maps.get("moneyFlowing_blockedBalance"));
        viewHolder.moneyFlowing_cash.setText(maps.get("moneyFlowing_cash"));
        viewHolder.moneyFlowing_earning.setText(maps.get("moneyFlowing_earning"));
        return convertView;
    }
    private class ViewHolder {
        //        TextView moneyFlowing_type;
        TextView moneyFlowing_name;
        TextView moneyFlowing_abstract;
        TextView moneyFlowing_annualRate;
        TextView moneyFlowing_projectTime;
        TextView moneyFlowing_payMode;
        TextView moneyFlowing_investMoney;
        TextView moneyFlowing_repayType;
        TextView moneyFlowing_startTime;
     //   TextView moneyFlowing_availableBalance;
        TextView moneyFlowing_blockedBalance;
        TextView moneyFlowing_cash;
        TextView moneyFlowing_earning;
    }
}
